<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Truck extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('truckmodel');
		$this->load->helper('flexigrid');
	}
	
public function index()
	{
		//ver lib
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		
		
		$colModel['larn'] = array('ชื่อลาน',40,TRUE,'center',1);
		$colModel['ticketid'] = array('เลขที่ใบชั่ง',60,TRUE,'center',2);
		$colModel['extra_paymentdate'] = array('วันที่จ่าย',180,TRUE,'left',1);
		$colModel['vendor_land_id'] = array('vendor code',120,TRUE,'left',1);
		$colModel['net_wght'] = array('น้ำหนักสุทธิ',130, TRUE,'left',0);
		$colModel['cost_unt'] = array('ราคาต่อหน่วย',80, TRUE, 'right',0);
		$colModel['totalcut_price'] = array('รวมหักเงิน',80, TRUE, 'right',0);
		$colModel['buynet'] = array('เงินซื้อสุทธิ',80, TRUE, 'right',0);
		$colModel['buynet1'] = array('เงินคงเหลือจ่าย',80, TRUE, 'right',0);
		$colModel['action'] = array('Actions',80, FALSE, 'right',0);
		
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => 400,
		'rp' => 15,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Displaying: {from} to {to} of {total} items.',
		'blockOpacity' => 0.5,
		'title' => 'Truck',
		'showTableToggleBtn' => true
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		$buttons[] = array('Delete','delete','test');
		$buttons[] = array('separator');
		$buttons[] = array('Select All','add','test');
		$buttons[] = array('DeSelect All','delete','test');
		$buttons[] = array('separator');

		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url('ajax/ajax_truck'),$colModel,'extra_paymentdate','asc',$gridParams,$buttons);
		
		$data['js_grid'] = $grid_js;
		$data['role_id']=$this -> session -> userdata('role_id');
		$this->load->view('truck/flexigrid',$data);
	}
	

	public function upload()
	{
		$this->load->model('optionmodel');
		$data['pos_option'] = $this->optionmodel->getPosOption();
		$data['role_id']=$this -> session -> userdata('role_id');
		$this->load->view('truck/upload',$data);
	}
	
	public function saveUpload(){
		$insert_larn = $this->input->post('larn');

		$upload_path = $this->truckmodel->saveUpload($insert_larn);
		echo $upload_path;
		$this->truckmodel->uploadCSV($upload_path,$insert_larn);
		
		//redirect('truck/upload');
	}
	
	public function testdate(){
		//phpinfo();
		$phpdate = '12/12/2010';
		$phpdate = substr($phpdate, 3,2);
		
		echo $phpdate;
		//echo DateTime::createFromFormat('d-m-Y', $phpdate)->format('Y-m-d');
	}
	
	public function testmd5(){
		echo md5_file(base_url('uploads_truck/larn1/09_01_2012_11_07_35.csv'));
		echo '/';
		echo md5_file(base_url('uploads_truck/larn1/09_01_2012_11_09_32.csv'));
		
	}
	

	


}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */